package com.rsscollector.model.vo;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;

@Entity
@Table(name = "USERS")
public class User implements Serializable {

    private Long id;
    private String email;
    private String password;
    private String firstName;
    private String lastName;

    private boolean accountDisabled = false;
    private boolean accountExpired = true;
    private boolean accountLocked = true;
    private boolean passwordExpired = true;
    
    private Collection<Privilege> privileges = new HashSet<Privilege>();
    
    // No-arg constructor
    public User() { /* empty */ }

    public User(String email, String password, String firstName, String lastName,
    	    boolean accountDisabled, boolean accountExpired, boolean accountLocked, boolean passwordExpired) {
        this.email = email;
        this.password = password;
        this.firstName = firstName;
        this.lastName = lastName;

        this.accountDisabled = accountDisabled; 
        this.accountExpired = accountExpired;
        this.accountLocked = accountLocked;
        this.passwordExpired = passwordExpired;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "USER_ID")
    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name = "EMAIL", unique = true, nullable = false, length = 50)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "FIRST_NAME", nullable = false, length = 100)
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column(name = "LAST_NAME", nullable = false, length = 100)
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Column(name = "PASSWORD", nullable = false, length = 100)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "ACCOUNT_DISABLED_FLAG", nullable = false)
	public boolean isAccountDisabled() {
		return accountDisabled;
	}

	public void setAccountDisabled(boolean accountDisabled) {
		this.accountDisabled = accountDisabled;
	}

	@Column(name = "ACCOUNT_EXPIRED_FLAG", nullable = false)
	public boolean isAccountExpired() {
		return accountExpired;
	}

	public void setAccountExpired(boolean accountExpired) {
		this.accountExpired = accountExpired;
	}

	@Column(name = "ACCOUNT_LOCKED_FLAG", nullable = false)
	public boolean isAccountLocked() {
		return accountLocked;
	}

	public void setAccountLocked(boolean accountLocked) {
		this.accountLocked = accountLocked;
	}

	@Column(name = "PASSWORD_EXPIRED_FLAG", nullable = false)
	public boolean isPasswordExpired() {
		return passwordExpired;
	}

	public void setPasswordExpired(boolean passwordExpired) {
		this.passwordExpired = passwordExpired;
	}

    @ManyToMany()
    public Collection<Privilege> getPrivileges() {
        return this.privileges;
    }

    public void setPrivileges(Collection<Privilege> privileges) {
        this.privileges = privileges;
    }	
}
